package com.hongye.app.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.alibaba.druid.util.StringUtils;
import com.hongye.app.model.AppVersionModel;
import com.hongye.app.model.BuyerAddressModel;
import com.hongye.app.model.BuyerStatisticsModel;
import com.hongye.app.model.EmployeeManageModel;
import com.hongye.app.model.EvaluationModel;
import com.hongye.app.model.FavoriteModel;
import com.hongye.app.model.FeedBackModel;
import com.hongye.app.model.GoodsCategroyModel;
import com.hongye.app.model.GoodsModel;
import com.hongye.app.model.NewRegionModel;
import com.hongye.app.model.PhoneCodeModel;
import com.hongye.app.model.ReturnGoodsModel;
import com.hongye.app.model.ShoppingCartModel;
import com.hongye.app.model.UserAppModel;
import com.hongye.app.model.ViewDetailModel;
import com.hongye.util.HuanXinUtils;
import com.hongye.util.JsonUtils;
import com.hongye.util.Utils;
import com.jfinal.aop.Clear;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.upload.UploadFile;

public class UserAppInfoController extends Controller {
	
	private Logger log = Logger.getLogger(getClass());
	public static String ImgPath = "http://120.27.117.192/rbg/upload/";//服务器图片路径
	private static String CATEGROY_ID = "1,2,3,4,5,6";//用户兴趣默认类别id集合
	private static String CATEGROY_IDS = "1,2,3,4,5,6";//搜索商品-获取推荐类别
	
	public UserAppInfoController() {
		
	}
	
	/**
	 * 参数接收——String
	 * this.getParam
	 * @author lifuqiang
	 * 2016-10-31
	 * @param param
	 * @return
	 */
	public String getPa(String param) {
		return this.getPara(param);
	}
	
	/**
	 * 参数接收——int
	 * this.getParaToInt
	 * @author lifuqiang
	 * 2016-11-14
	 * @return
	 */
	@Clear
	public int getParaInt(String param){
		return this.getParaToInt(param);
	}
	
	/**
	 * 参数接收——UploadFile
	 * this.getFile
	 * @author lifuqiang
	 * 2017-2-4
	 * @return
	 */
	public UploadFile getfile(String fileName){
		int maxPostSize = 20 * 1024 * 1024;
		return this.getFile(fileName, "", maxPostSize);
	}
	
	/**
	 * 用户登录 
	 */
	@Clear
	public void login() {
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("state", "fal");
		rs.put("isshop",0);
		String phone = this.getPa("phone");
		if (UserAppModel.dao.chkAppUser(phone, Utils.strToMD5(this.getPa("passwd")))) {
			BuyerStatisticsModel buyerStatisticsModel = BuyerStatisticsModel.dao.findFirst("select * from buyer_statistics where buyer_phone=" + phone);
			rs.put("state", "suc");
			if(buyerStatisticsModel != null){
				UserAppModel userinfo = UserAppModel.dao.findFirst("select * from buyer where phone = " + phone);
				rs.put("isshop", buyerStatisticsModel.get("isshop"));
				rs.put("nick", userinfo.get("nick"));
				rs.put("user_id", userinfo.getInt("user_id"));
				rs.put("sex", userinfo.getInt("sex"));
				rs.put("status", userinfo.getInt("status"));
				rs.put("phone", phone);
				if(StringUtils.isEmpty(userinfo.getStr("avatar"))){
					rs.put("avatar", ImgPath + "defaultavatar.png");
				}else{
					rs.put("avatar", ImgPath + userinfo.get("avatar"));
				}
			}
		}
		this.renderJson(rs);
	}
	
	/**
	 * 进入注册页面
	 * @author liushaomin
	 * 2017年8月14日
	 */
	@Clear
	public void regUser_one() {
		Map<String, Object> rs = new HashMap<String, Object>();
		PhoneCodeModel phonecode = new PhoneCodeModel();
		phonecode.set("token", Utils.getRandomString(4)).save();
		rs.put("tokenid", phonecode.get("id"));
		rs.put("token", phonecode.get("token"));
		this.renderJson(rs);
	}

	/**
	 * 提交注册用户
	 * @author liushaomin
	 * 2017年8月14日
	 * state=1,两次密码不同
	 * state=2,注册成功
	 * state=3注册失败
	 * state=4验证码错误
	 */
	@Clear
	public void regUser() {
		Map<String, Object> rs = new HashMap<String, Object>();
		String code = this.getPa("code");
		String phone = this.getPa("phone");
		String pwd = getPa("pwd");
		String repwd = getPa("repwd");
		rs.put("state", 1);
		if(!StringUtils.isEmpty(pwd) && !StringUtils.isEmpty(repwd) && pwd.equals(repwd)){
			if(UserAppModel.chkAppSMS(phone, code, "reguser")){//校验验证码是否正确
				UserAppModel user = new UserAppModel();
				boolean flag = user.set("phone", phone).set("nick", Utils.getUserNick()).set("sex", 0).set("password",  Utils.strToMD5(pwd)).set("status", 0).save();
				if(flag){//添加用户统计表信息；用户默认兴趣类别集合；默认0为未开通店铺
					System.err.println("yanzhengmashifouzhengque ");
					BuyerStatisticsModel bs = new BuyerStatisticsModel();
					bs.set("buyer_id", user.get("user_id")).set("buyer_phone", user.get("phone")).set("isshop", 0).set("categroy_id", CATEGROY_ID).save();
					HuanXinUtils.addUsers(phone, pwd ,phone);//注册环信 密码未加密
				}
				rs.put("state", flag ? 2 : 3);
			}else{
				rs.put("state", 4);
			}
		}
		this.renderJson(rs);
	}
	
	/**
	 * 注册——发送短信验证码接口
	 * @author liushaomin
	 * 2016年10月4日
	 * state fal 发送失败，suc发送成功， isexists该手机号已注册
	 */
	@Clear
	public void reg_sendSMS() {
		String code = Utils.randomCode();
		String phone = this.getPa("phone");
		String apptoken = this.getPa("apptoken");
		String tokenid = this.getPa("tokenid");
		String type = this.getPa("type");
		String ip = this.getPa("ip");
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("state", "fal");
			//校验手机号是否注册
		if (UserAppModel.findByPhone(phone)){
			rs.put("state", "isexists");//已注册
		}else{
			PhoneCodeModel phonecode = PhoneCodeModel.dao.findById(tokenid);
			if(Utils.validate(tokenid, phone, apptoken)){// 平台验证
				//验证通过后 更改token
				phonecode.set("token", Utils.getRandomString(4)).update();
				PhoneCodeModel old_phonecode = PhoneCodeModel.get(phone, "reguser");
				boolean boo = false ;
				if(old_phonecode == null){
					boo = phonecode.set("type", type).set("phone", phone).set("code", code).set("c_time", Utils.getDate()).update();
				}else{
					long time =  Utils.getLongTime(old_phonecode.get("c_time").toString());
					if(time > 60*1000){
						boo = phonecode.set("type", type).set("phone", phone).set("code", code).set("c_time", Utils.getDate()).update();
					}
				}
				if(boo){
					Utils.sendSMS(phone, code);
					rs.put("state", "suc");
				}
			}
		}
		this.renderJson(rs);
	}
	
	/**
	 * 进入找回秘密页面 第一步
	 * @author liushaomin
	 * 2017年8月14日
	 */
	@Clear
	public void findpwd() {
		Map<String, Object> rs = new HashMap<String, Object>();
		PhoneCodeModel phonecode = new PhoneCodeModel();
		phonecode.set("token", Utils.getRandomString(4)).save();
		rs.put("tokenid", phonecode.get("id"));
		rs.put("token", phonecode.get("token"));
		this.renderJson(rs);
	}
	
	/**
	 * 找回密码时 发送验证码接口
	 * @author liushaomin
	 * 2017年8月15日
	 */
	@Clear
	public void find_sendSMS() {
		String code = Utils.randomCode();
		String phone = this.getPa("phone");
		String apptoken = this.getPa("apptoken");
		String tokenid = this.getPa("tokenid");
		String type = this.getPa("type");
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("state", "noreg");//未注册
		if (UserAppModel.findByPhone(phone)){
			rs.put("state", "fal");
			PhoneCodeModel phonecode = PhoneCodeModel.dao.findById(tokenid);
			if(Utils.validate(tokenid, phone, apptoken)){// 平台验证
				PhoneCodeModel old_phonecode = PhoneCodeModel.get(phone, "findpwd");
				boolean boo = false ;
				if(old_phonecode == null){
					boo = phonecode.set("type", type).set("phone", phone).set("code", code).set("c_time", Utils.getDate()).update();
				}else{
					long time =  Utils.getLongTime(old_phonecode.get("c_time").toString());
					if(time > 60*1000){
						boo = phonecode.set("type", type).set("phone", phone).set("code", code).set("c_time", Utils.getDate()).update();
					}
				}
				if(boo){
					Utils.sendSMS(phone, code);
					rs.put("state", "suc");
				}
			}
		}
		this.renderJson(rs);
	}
	
	/**
	 *  密码重置(忘记密码时，重新设置密码) 第二步
	 * @author liushaomin
	 * 2016年12月21日
	 */
	@Clear
	public void setpwd(){
		String phone=this.getPa("phone");
		String pwd=this.getPa("pwd");
		Map<String, Object> rs=new HashMap<String, Object>();
		rs.put("state", "fal");
		if(null==phone||phone.trim().length()<11) return ;
		UserAppModel buyer = UserAppModel.getByPhone(phone);
		if(buyer.set("password", Utils.strToMD5(pwd)).update()){
			HuanXinUtils.resetPassword(phone, pwd);//修改环信密码 暂时未加密
			rs.put("state", "suc");
		}
		this.renderJson(rs);
	}
	
	/**
	 * 绑定银行卡时 发送的验证码
	 * @author liushaomin
	 * 2017年8月15日
	 */
	@Clear
	public void bankcard_sendSMS() {
		String code = Utils.randomCode();
		String phone = this.getPa("phone");
		String apptoken = this.getPa("apptoken");
		String tokenid = this.getPa("tokenid");
		String type = this.getPa("type");
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("state", "fal");
		PhoneCodeModel phonecode = PhoneCodeModel.dao.findById(tokenid);
		if(Utils.validate(tokenid, phone, apptoken)){// 平台验证
			PhoneCodeModel old_phonecode = PhoneCodeModel.get(phone, "bankcard");
			boolean boo = false ;
			if(old_phonecode == null){
				boo = phonecode.set("type", type).set("phone", phone).set("code", code).set("c_time", Utils.getDate()).update();
			}else{
				long time =  Utils.getLongTime(old_phonecode.get("c_time").toString());
				if(time > 60*1000){
					boo = phonecode.set("type", type).set("phone", phone).set("code", code).set("c_time", Utils.getDate()).update();
				}
			}
			if(boo){
				Utils.sendSMS(phone, code);
				rs.put("state", "suc");
			}
		}
		this.renderJson(rs);
	}
	
	/**
	 * 找回密码——校验验证码是否正确
	 * @author liushaomin
	 * 2016年10月4日
	 */
	@Clear
	public void findpwd_chkAppSMS(){
		String phone = this.getPa("phone");
		String code = this.getPa("code");
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("state", "fal");
		if(UserAppModel.chkAppSMS(phone, code, "findpwd")){
			rs.put("state", "suc");
		}
		this.renderJson(rs);
	}

	/**
	 * 通过搜索关键字获取所有商品(APP)
	 * 已分页
	 * @author lifuqiang
	 * 2016-11-1
	 */
	@Clear
	public void getGoodsByKey(){
		Map<String, Object> rs = new HashMap<String, Object>();
		Page<GoodsModel> goodslist = GoodsModel.dao.getGoodsByKey(getPa("key"), getParaInt("pageNumber"));
		for(GoodsModel goods : goodslist.getList()){
			goods.set("thumb",  ImgPath +goods.get("thumb"));
			goods.put("shop_name", BuyerStatisticsModel.getShop_name(goods.getStr("seller_id")));
			goods.put("shop_address", BuyerStatisticsModel.getAddress(goods.getStr("seller_id")));
		}
		rs.put("goods", goodslist);
		this.renderJson(rs);
	}
	
	/**
	 * 商品详情，返回json数据
	 */
	@Clear
	public void goodsDetail() {
		int gid = getParaInt("gid");
		Map<String, Object> rs = new HashMap<String, Object>();
		GoodsModel goods = GoodsModel.dao.getGoods(gid);
		String seller_id = goods.getStr("seller_id");
		String sql2 = "select * from favorite f, buyer b where f.from_phone = '"+getPa("phone")+"'and f.to_phone = b.phone and b.user_id = '"+seller_id+"'";
		FavoriteModel favorite = new FavoriteModel().findFirst(sql2);
		if(favorite == null){
			goods.put("isguanzhu", "1");
		}else{
			goods.put("isguanzhu", "0");
		}
		goods.put("num", goods.get("sales"));
		goods.put("shop_avatar",ImgPath + BuyerStatisticsModel.getStatisticsByID(seller_id).get("shop_avatar"));
		goods.put("shop_name", BuyerStatisticsModel.getStatisticsByID(seller_id).get("shop_name"));
		goods.set("videoname", ImgPath + goods.getStr("videoname"));
		goods.set("thumb", ImgPath + goods.getStr("thumb"));
		rs.put("goods", goods);
		this.renderJson(rs);
	}
	
	/**
	 * 商品详情，返回json数据
	 */
	@Clear
	public void goodsDetail2() {
		int gid = getParaInt("gid");
		Map<String, Object> rs = new HashMap<String, Object>();
		GoodsModel goods = GoodsModel.dao.getGoods(gid);
		if(goods != null && goods.getInt("sale") != 1){
			String seller_id = goods.getStr("seller_id");
			String sql2 = "select * from favorite f, buyer b where f.from_phone = '"+getPa("phone")+"'and f.to_phone = b.phone and b.user_id = '"+seller_id+"'";
			FavoriteModel favorite = new FavoriteModel().findFirst(sql2);
			if(favorite == null){
				goods.put("isguanzhu", "1");
			}else{
				goods.put("isguanzhu", "0");
			}
			goods.put("num", goods.get("sales"));
			goods.set("videoname", ImgPath + goods.getStr("videoname"));
			goods.set("thumb", ImgPath + goods.getStr("thumb"));
			rs.put("goods", goods);
			rs.put("state", "suc");
		}
		rs.put("state", "fal");
		this.renderJson(rs);
	}
	
	/**
	 * 商品详情 返回web页面
	 * @author liushaomin
	 * 2016年10月8日
	 */
	@Clear
	public void webgoodsDetail() {
		int gid = getParaInt("gid");
		String fromphone = getPa("fromphone");
		String fromip = getPa("fromip");
		ViewDetailModel.addViewDetail(fromphone, fromip, gid);
		GoodsModel goodm = GoodsModel.dao.getGoods(gid);
		if(goodm != null && goodm.getInt("sale") != 1){
			String seller_id = goodm.getStr("seller_id");
			String sql2 = "select * from favorite f, buyer b where f.from_phone = '"+getPa("phone")+"'and f.to_phone = b.phone and b.user_id = '"+seller_id+"'";
			FavoriteModel favorite = new FavoriteModel().findFirst(sql2);
			if(favorite == null){
				goodm.put("isguanzhu", "1");
			}else{
				goodm.put("isguanzhu", "0");
			}
			List<EvaluationModel> evaluationlist = EvaluationModel.dao.getEvaluById(gid);
			this.setAttr("postage", BuyerStatisticsModel.getShopPostage(goodm.getStr("phone")));
			this.setAttr("evaluation", evaluationlist);
			this.setAttr("g", goodm);
			this.renderJsp("./goodsDetail.jsp");
		}else{
			this.renderJsp("./404.jsp");
		}
	}
	
	@Clear
	public void goodsDetail_Comment() {
		getParaInt("pageNumber");
		Page<EvaluationModel> list = EvaluationModel.getEvaluationPageNumber(getParaInt("gid"),getParaInt("pageNumber"));
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("state", list.getList());
		this.setAttr("evaluation", list.getList());
		this.renderJsp("./ajaxComment.jsp");
	}
		
	/**
	 * 添加商品。add by changpf at 2016年9月12日20:23:37
	 * @throws Exception
	 */
	@Clear
	public void addGoods(){
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("state", "fail");
		UploadFile gimg = getfile("gimg");
		UploadFile gvdo = getfile("gvdo");
		String real_price = this.getPa("gprice");
		if(getParaInt("vdosize")==gvdo.getFile().length()){
			UserAppModel user = UserAppModel.dao.findFirst("select * from buyer where phone = '"+ getPa("phone") +"'");
			// 插入商品基本信息
			new GoodsModel().set("g_name", getPa("gname")).set("seller_id", user.get("user_id")).set("c_id", getPa("gtypeid"))
			.set("real_price",Double.parseDouble(real_price)).set("thumb", gimg.getFileName()).set("audit", 0).set("sales", 0)
			.set("content", getPa("content")).set("videoname", gvdo.getFileName()).set("sale", 0).set("stock", getPa("stock")).set("ratio",  getPa("ratio")).save();
			rs.put("state", "suc");
		}else{
			rs.put("state", "fal");
		}
		this.renderJson(rs);
	}
	
	/**
	 * 上传商品时获取所有商品类别
	 * @author lifuqiang
	 * 2016-10-12
	 */
	@Clear
	public void goodsCategroyAll(){
		BuyerStatisticsModel statistics = BuyerStatisticsModel.getStatistics(getPa("phone"));
		String sql = "select * from goods_categroy where showg=0 and id in ("+statistics.getStr("shop_saletype")+") order by pid";
		List<GoodsCategroyModel> lis = GoodsCategroyModel.dao.find(sql);
		Map<String, Object> map = new HashMap<String, Object>();
		Map<String, Object> rs = new HashMap<String, Object>();
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		List<Map<String, Object>> list_1th = new ArrayList<Map<String, Object>>();
		for(GoodsCategroyModel gcm1 : lis){
			Map<String, Object> rs2 = new HashMap<String, Object>();
			List<Map<String, Object>> list_2nd = new ArrayList<Map<String,Object>>();
			rs2.put("id", gcm1.get("id"));
			rs2.put("name", gcm1.get("c_name"));
			rs2.put("thumb", ImgPath + (String)gcm1.get("thumb"));
			list_1th.add(rs2);
			String sql2 = "select * from goods_categroy where showg=0 and pid > "+gcm1.get("pid")+" * 100 and pid < ("+gcm1.get("pid")+" + 1) * 100 order by pid";
			List<GoodsCategroyModel> list_2th = GoodsCategroyModel.dao.find(sql2);
			for(GoodsCategroyModel gcm2 : list_2th){
				Map<String, Object> rs3 = new HashMap<String, Object>();
				rs3.put("id", gcm2.get("id"));
				rs3.put("name",gcm2.get("c_name"));
				list_2nd.add(rs3);
				rs2.put("two_name", list_2nd);
			}
		}
		rs.put("one_name", list_1th);
		list.add(rs);
		map.put("goodscategroy", list);
		this.renderJson(map);
	}
	
	/**
	 * 首页 发现接口
	 * @author liushaomin
	 * 2017年7月6日
	 */
	@Clear
	public void getAllGoodsByCate(){
		Page<GoodsModel> list = GoodsModel.getGoodsByFaXian(getParaInt("pageNumber"));
		for (GoodsModel goods : list.getList()) {
			UserAppModel user = UserAppModel.dao.findById(goods.get("seller_id"));
			goods.set("thumb", ImgPath + goods.getStr("thumb"));
			goods.put("nick", user.get("nick"));
			goods.put("avatar", ImgPath + user.get("avatar"));
			goods.put("shop_name", BuyerStatisticsModel.getShop_name(goods.getStr("seller_id")));
			goods.put("shop_address", BuyerStatisticsModel.getAddress(goods.getStr("seller_id")));
		}
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("goods", list);
		this.renderJson(rs);
	}
	
	/**
	 * 获取已关注的人所发布的商品
	 * 已添加分页
	 * @author lifuqiang
	 * 2016-10-8
	 */
	@Clear
	public void getGoodsByFavorite(){
		Page<GoodsModel> goods = GoodsModel.dao.getGoodsByFavorite(getPa("phone"), getParaInt("pageNumber"));
		for(GoodsModel item : goods.getList()){
			UserAppModel user = UserAppModel.dao.findById(item.get("seller_id"));
			item.put("thumb", ImgPath + item.getStr("thumb"));
			item.put("nick", user.get("nick"));
			item.put("avatar", ImgPath + user.get("avatar"));
			item.put("shop_name", BuyerStatisticsModel.getShop_name(item.getStr("seller_id")));
			item.put("shop_address", BuyerStatisticsModel.getAddress(item.getStr("seller_id")));
		}
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("goods", goods);
		this.renderJson(rs);
	}
	
	/**
	 * 首页自营五大类别入口
	 * 休闲零食（前台显示）对应零食（后台商品类别定义）pid=5
	 * 日常食品（前台显示）对应食品（后台商品类别定义）pid=3
	 * 洗护美妆 （前台显示）对应美妆（后台商品类别定义）pid=1
	 * 纸品家清 （前台显示）对应个人护理（后台商品类别定义）pid=2
	 * 酒水乳饮 （前台显示）对应 后台的二级类别 id=64,65,66,67,68,71,72,73,74,75
	 * @author liushaomin
	 * 2017年8月25日
	 */
	@Clear
	public void getIndexZiYing(){
		String typename = getPa("typename");
		int pagenumber = getParaInt("pageNumber");
		String goods_categroy_id = "";
		if(typename.equals("休闲零食")){
			goods_categroy_id = GoodsCategroyModel.getTwoLevelid(5);
		}else if(typename.equals("日常食品")){
			goods_categroy_id = GoodsCategroyModel.getTwoLevelid(3);
		}else if(typename.equals("洗护美妆")){
			goods_categroy_id = GoodsCategroyModel.getTwoLevelid(1);
		}else if(typename.equals("纸品家清")){
			goods_categroy_id = GoodsCategroyModel.getTwoLevelid(2);
		}else{
			goods_categroy_id = "64,65,66,67,68,71,72,73,74,75";
		}
		Page<GoodsModel> goods = GoodsModel.getIndexZiYing(goods_categroy_id, pagenumber);
		for(GoodsModel item : goods.getList()){
			UserAppModel user = UserAppModel.dao.findById(item.get("seller_id"));
			item.put("thumb", ImgPath + item.getStr("thumb"));
			item.put("nick", user.get("nick"));
			item.put("avatar", ImgPath + user.get("avatar"));
			item.put("shop_name", BuyerStatisticsModel.getShop_name(item.getStr("seller_id")));
			item.put("shop_address", BuyerStatisticsModel.getAddress(item.getStr("seller_id")));
		}
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("goods", goods);
		this.renderJson(rs);
	}
	
	
	
	
	/**
	 * 上下架商品
	 * 软删除，是否显示，前段做判断处理
	 * @author lifuqiang
	 * 2016-10-20
	 */
	@Clear
	public void goodsSale(){
		GoodsModel goodsmodel = GoodsModel.dao.findById(getPa("goodsid"));
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("state", "fal");
		boolean boo = goodsmodel.set("sale", getPa("state")).update();
		if(boo){
			rs.put("state", "suc");
		}
		this.renderJson(rs);
	}
	
	/**
	 * 1.商品删除，彻底删除，不可恢复；
	 * 2.可批量
	 * 3.被操作中的商品不能删除
	 * 4.购物车商品不能显示商品信息了
	 * TODO 未完成，涉及甚广，请君慎用！！！！！！
	 * @author lifuqiang
	 * 2016-12-8
	 */
	@Clear
	public void deleteGoods(){
		Map<String, Object> rs = new HashMap<String, Object>();
		boolean boo = true;
		rs.put("state", "fal");
		String goodsid = getPa("goodsid");
		String[] strgoodsids  = goodsid.split(",");
		for (int i = 0; i < strgoodsids.length; i++) {
			boolean bool = new GoodsModel().deleteById(strgoodsids[i]);
			if(!bool){
				boo = false;
				return;
			}
		}
		if(boo){
			rs.put("state", "suc");
		}
		this.renderJson(rs);
	}
	
	/**
	 * 商家得到商品信息
	 * @author liushaomin
	 * 2017年7月28日
	 */
	@Clear
	public void goodsDetail_Seller() {
		int gid = getParaInt("gid");
		Map<String, Object> rs = new HashMap<String, Object>();
		GoodsModel goods = GoodsModel.dao.getGoods_Seller(gid);
		goods.set("thumb", ImgPath + goods.getStr("thumb"));
		rs.put("goods", goods);
		this.renderJson(rs);
	}
	
	/**
	 * 商家编辑商品
	 * @author lifuqiang
	 * 2016-10-20
	 */
	@Clear
	public void editGoods(){
		GoodsModel goodsmodel = GoodsModel.dao.findById(getParaInt("goodsid"));
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("state", "fal");
		boolean boo = goodsmodel.set("g_name", getPa("gname")).set("real_price", getPa("gprice")).set("c_id", getPa("gtypeid")).set("stock", getPa("stock"))
					.set("content", getPa("content")).update();
		if(boo){
			rs.put("state", "suc");
		}
		this.renderJson(rs);
	}
	
	/**
	 * 修改密码
	 * @author liushaomin
	 * 2016年12月21日
	 */
	@Clear
	public void setnewpwd() {
		String phone=this.getPa("phone");
		String oldpwd=this.getPa("oldpwd");
		String pwd=this.getPa("pwd");
		if(null==phone||phone.trim().length()<11) return ;
		String sql="select * from buyer where phone='"+phone+"'  and password='"+Utils.strToMD5(oldpwd)+"'";
		Map<String, String> rs=new HashMap<String, String>();
		UserAppModel buyer = new UserAppModel();
		buyer = UserAppModel.dao.findFirst(sql);
		if(buyer != null){
			if(buyer!=null&&buyer.set("password", Utils.strToMD5(pwd)).update()){
				HuanXinUtils.resetPassword(phone, pwd);//修改环信的登录密码 暂时未加密
				rs.put("state", "0");
			}else{
				rs.put("state", "2");
			}
		}else{
			rs.put("state", "1");
		}
		this.renderJson(rs);
	}
	
	/**
	 * 修改个人信息-头像
	 * @author lifuqiang
	 * 2016-10-20
	 * @throws Exception
	 */
	@Clear
	public void setAvatar(){
		UploadFile avatar = getfile("avatar");
		String sql="select * from buyer where phone='"+ getPa("phone") +"' ";
		Map<String, String> rs=new HashMap<String, String>();
		rs.put("state", "fal");
		UserAppModel buyer=new UserAppModel().findFirst(sql);
		if(buyer.set("avatar", avatar.getFileName()).update()){
			rs.put("state", "suc");
		}
		this.renderJson(rs);
	}
	
	/**
	 * 修改个人信息-性别
	 * @author lifuqiang
	 * 2016-10-20
	 */
	@Clear
	public void setSex(){
		String sql="select * from buyer where phone='"+getPa("phone")+"' ";
		Map<String, String> rs=new HashMap<String, String>();
		rs.put("state", "fal");
		UserAppModel buyer=new UserAppModel().findFirst(sql);
		if(buyer.set("sex", getPa("sex")).update()){
			rs.put("state", "suc");
		}
		this.renderJson(rs);
	}
	
	/**
	 * 修改个人信息-昵称
	 * @author lifuqiang
	 * 2016-10-20
	 */
	@SuppressWarnings("null")
	@Clear
	public void setNick(){
		String nick = this.getPa("nick");
		String sql="select * from buyer where phone='"+getPa("phone")+"' ";
		Map<String, String> rs=new HashMap<String, String>();
		rs.put("state", "fal");
		UserAppModel buyer=new UserAppModel().findFirst(sql);
		if(null != nick || nick.trim().length() != 0){
			boolean boo = buyer.set("nick", nick).update();
			if(boo){
				HuanXinUtils.resetNickName(getPa("phone"), nick);
				rs.put("state", "suc");
			}
		}
		this.renderJson(rs);
	}
	
	/**
	 *  获得个人信息
	 *  头像,名称,是否开通店铺,各种订单数量
	 * @author liushaomin
	 * 2017年3月14日
	 */
	@Clear
	public void getUserInfo(){
		String phone = getPa("phone");
		Map<String, Object> rs = new HashMap<String, Object>();
		if( phone.equals("")){
			rs.put("userinfo", null);
			this.renderJson(rs);
		}else{
			String sql="select avatar, nick, sex, phone, status, user_id from buyer where phone='"+phone+"' ";
			UserAppModel buyer = UserAppModel.dao.findFirst(sql);
			BuyerStatisticsModel buyersm = BuyerStatisticsModel.findByUser_id(buyer.get("user_id").toString());
			buyer.put("isshop", buyersm.get("isshop"));
			buyer.set("avatar", ImgPath + buyer.getStr("avatar"));
			rs.put("userinfo", buyer);
			rs.put("buyers_order", UserAppModel.getBuyersOrdernum(phone));
			rs.put("seller_order", UserAppModel.getSellerOrdernum(phone));
			this.renderJson(rs);
		}
	}
	
	/**
	 * 商品管理 自己发布商品的列表
	 * 已分页处理
	 * 已上架商品0
	 * @author liushaomin
	 * 2016年10月6日
	 */
	@Clear
	public void saleshipments(){
		Page<GoodsModel> goods_list = GoodsModel.dao.saleshipments(getPa("phone"), getParaInt("pageNumber"),0);
		for (GoodsModel item : goods_list.getList()) {
			item.set("thumb", ImgPath + item.get("thumb"));
		}
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("goods", goods_list);
		this.renderJson(rs);
	}
	
	/**
	 * 商品管理 自己发布商品的列表 
	 * 已分页处理
	 * 已下架商品1
	 * @author lifuqiang
	 * 2016-10-26
	 */
	@Clear
	public void nosaleshipments(){
		Page<GoodsModel> goods_list = GoodsModel.dao.saleshipments(getPa("phone"), getParaInt("pageNumber"),1);
		for (GoodsModel item : goods_list.getList()) {
			item.set("thumb", ImgPath + item.get("thumb"));
		}
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("goods", goods_list);
		this.renderJson(rs);
	}
	
	/**
	 * 添加地址的时候 获取省市区
	 * @author liushaomin
	 * 2016年10月7日
	 */
	@Clear
	public void regionaddress(){
		String sql = "select * from newregion where parentid = '000000'";
		List<NewRegionModel> province = new NewRegionModel().find(sql);
		Map<String, Object> rs = new HashMap<String, Object>();
		List<Object> list = new ArrayList<Object>();
		List<NewRegionModel> city = new ArrayList<NewRegionModel>();
		List<NewRegionModel> area = new ArrayList<NewRegionModel>();
		for (NewRegionModel itemprovince : province) {
			String id = itemprovince.getStr("id").substring(0, 2);
			String sql2 = "select * from newregion where id LIKE '"+ id +"%00' and id != '"+ id +"0000'";
			city.clear();
			city = new NewRegionModel().find(sql2);
			List<Object> citys = new ArrayList<Object>();
			for (NewRegionModel itemcity : city) {
				String areacode = itemcity.getStr("areacode");
				String sql3 = "select * from newregion where areacode = '"+ areacode +"' and parentid != '000000' and parentid != '"+ id +"0000'";
				List<String> list2 = new ArrayList<String>();
				Map<String, Object> map3 = new HashMap<String, Object>();
				area = new NewRegionModel().find(sql3);
				for (NewRegionModel itemarea : area) {
					list2.add(itemarea.getStr("name"));
				}
				map3.put("name", itemcity.get("name"));
				map3.put("county",list2);
				citys.add(map3);
			}
			Map<String, Object> map1 = new HashMap<String, Object>();
			map1.put("name", itemprovince.get("name"));
			map1.put("city", citys);
			list.add(map1);
		}
		rs.put("province", list);
		this.renderJson(rs);
	}
	
	/**
	 * 获取所有市
	 * @author liushaomin
	 * 2017年2月23日
	 */
	@Clear
	public void regioncity(){
		Map<String, Object> rs = new HashMap<String, Object>();
		String sql = "select n.name from newregion n where parentid LIKE '%0000'AND postcode != ''";
		List<NewRegionModel> city = NewRegionModel.dao.find(sql);
		rs.put("city", city);
		this.renderJson(rs);
	}
	
	/**
	 * 获取用户 购物车
	 * @author liushaomin
	 * 2016年10月8日
	 */
	@Clear
	public void shoppingcart(){
		String phone = getPa("phone");
		List<UserAppModel> user_list = UserAppModel.dao.shoppingcart(phone);
		for(UserAppModel user : user_list){
			String sql2 = "select s.id, goods_id from shoppingcart s, goods g where s.phone = '"+phone+"' and "+user.getInt("user_id")+" = g.seller_id AND g.id = s.goods_id order by s.c_time";
			String sql_shop = "select * from buyer_statistics where buyer_phone = '"+user.get("phone")+"'";
			List<ShoppingCartModel> list_cate = new ShoppingCartModel().find(sql2);
			BuyerStatisticsModel bs = BuyerStatisticsModel.dao.findFirst(sql_shop);
			Map<String, Object> map = new HashMap<String, Object>();
			for(ShoppingCartModel cate : list_cate){
				if(cate != null){
					String sql3 = "select s.id, goods_id, num, thumb, real_price, g_name, seller_id, sale, g.c_time from shoppingcart s, goods g where s.id = "+cate.get("id")+" and g.id = "+cate.get("goods_id")+" AND s.goods_id = g.id order by g.c_time";
					GoodsModel goods = GoodsModel.dao.findFirst(sql3);
					if(goods != null){
						cate.put("num", goods.get("num"));
						cate.put("thumb", ImgPath + goods.get("thumb"));
						cate.put("real_price", goods.get("real_price"));
						cate.put("g_name", goods.get("g_name"));
						cate.put("seller_id", goods.get("seller_id"));
						cate.put("sale", goods.get("sale"));
						cate.put("phone", user.get("phone"));
						cate.put("shop_name",  bs.get("shop_name"));
					}	
				}
			}
			map.put("cate", list_cate);
			user.put("catelist",map);
			user.put("shop_avatar", ImgPath + bs.get("shop_avatar"));
			user.put("shop_name", bs.get("shop_name"));
		}
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("shoppingcart", user_list);
		this.renderJson(rs);
	}
	
	/**
	 * 添加购物车
	 * @author lifuqiang
	 * 2016-10-9
	 */
	@Clear
	public void addshoppingcart(){
		String phone = this.getPa("phone");
		String goodsid = this.getPa("goodsid");
		int num = this.getParaToInt("num");
		String sql = "select * from shoppingcart where phone='"+phone+"' and goods_id='"+goodsid+"'";
		ShoppingCartModel cart = ShoppingCartModel.dao.findFirst(sql);
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("state", "fal");
		if(cart!=null){	//如果购物车已存在这个商品，在原有基础上更新
			if(new ShoppingCartModel().findFirst(sql).set("num", (cart.getInt("num")+num)).update()){//计算新的商品个数并更新
				rs.put("state", "suc");
			}
		}else{		//如果购物车没有这个商品，添加新的
			if(new ShoppingCartModel().set("phone", phone).set("goods_id", goodsid).set("num", num).set("c_time", Utils.getDate()).save()){
				rs.put("state", "suc");
			}
		}
		this.renderJson(rs);
		
	}
	
	/**
	 * 删除购物车
	 * @author lifuqiang
	 * 2016-10-9
	 */
	@Clear
	public void removeshoppingcart(){
		String shoppingcartid = this.getPa("shoppingcartid");
		String[] shoppingcartids  = shoppingcartid.trim().split(",");
		Map<String, Object> rs = new HashMap<String, Object>();
		boolean result = false;
		rs.put("state", "fal");
		for(String ids : shoppingcartids){
			if(new ShoppingCartModel().deleteById(ids)){
				result = true;
			}else{
				result = false;
			}
		}
		if(result){
			rs.put("state", "suc");
		}
		this.renderJson(rs);
	}
	
	/**
	 * 修改购物车中的商品数量
	 * @author liushaomin
	 * 2016年10月18日
	 */
	@Clear
	public void editgoodstnum(){
		String shoppingcartid = this.getPa("id");
		String num = this.getPa("num");
		ShoppingCartModel sc = ShoppingCartModel.dao.findById(shoppingcartid);
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("state", "fal");
		boolean boo = sc.set("num", Integer.valueOf(num)).update();
		if (boo) {
			rs.put("state", "suc");
		}
		this.renderJson(rs);
	}
	
	
	/**
	 * 收货地址列表
	 * @author lifuqiang
	 * 2016-10-8
	 */
	@Clear
	public void shippingAddressList(){
		String phone = this.getPa("phone");
		String sql = "select * from buyer_address where user_phone='"+phone+"'";
		List<BuyerAddressModel> lis = BuyerAddressModel.dao.find(sql);
		if(log.isInfoEnabled()){log.info(""+lis);}
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("address", lis);
		this.renderJson(rs);
		
	}
	
	/**
	 * 删除收货地址
	 * @author lifuqiang
	 * 2016-10-8
	 */
	@Clear
	public void removeShippingAddress(){
		String addressId = this.getPa("id");
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("state", "fal");
		if(Db.deleteById("buyer_address", addressId)){
			rs.put("state", "suc");
		}
		this.renderJson(rs);
	}
	
	/**
	 * 设置默认地址
	 * @author lifuqiang
	 * 2016-10-8
	 */
	@Clear
	public void defaultAddress(){
		String phone = this.getPa("phone");
		String addressId = this.getPa("id");
		String sql = "select * from buyer_address where id = '"+addressId+"'";
		String sql2 = "select * from buyer_address where user_phone='"+phone+"' and state=0";//查出用户的默认收货地址
		BuyerAddressModel buyeraddress1 = BuyerAddressModel.dao.findFirst(sql);
		BuyerAddressModel buyeraddress2 = BuyerAddressModel.dao.findFirst(sql2);
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("state", "fal");
		if(buyeraddress1!=null){	//ID是否为空
			if(buyeraddress2 == null){	//不存在
				if(buyeraddress1.set("state", 0).update()){//把这个状态为1的地址更新为状态0
					rs.put("state", "suc");
				}
			}else{//存在
				if(buyeraddress2.set("state", 1).update()){//把这个状态为0的设置为1
					if(buyeraddress1.set("state", 0).update()){//把这个地址的状态设置为0
						rs.put("state", "suc");
					}
				}
			}
		}
		this.renderJson(rs);
	}
	
	/**
	 * 得到默认地址
	 * @author lifuqiang
	 * 2016-11-8
	 */
	@Clear
	public void getDefaultAddress(){
		String phone = this.getPa("phone");
		BuyerAddressModel address = BuyerAddressModel.getDefaultAddress(phone);
		Map<String, Object> rs = new HashMap<String, Object>();
		Map<String, Object> map = new HashMap<String, Object>();
		if(address!=null){
			address.put("isexist", 0);
			rs.put("DefaultAddress", address);
		}else{
			map.put("isexist", 1);
			rs.put("DefaultAddress", map);
		}
		this.renderJson(rs);
	}
	
	/**
	 * 增加收貨地址
	 * @author lifuqiang
	 * 2016年10月9日
	 */
	@Clear
	public void addAddress(){
		String userphone = this.getPa("userphone");
		String phone = this.getPa("phone");
		String consignee = this.getPa("consignee");
		String country = this.getPa("country");
		String province = this.getPa("province");
		String city = this.getPa("city");
		String district = this.getPa("district");
		String address = this.getPa("address");
		String zipcode = this.getPa("zipcode");
		int state = this.getParaToInt("state");
		String sql = "select * from buyer_address where user_phone='"+userphone+"'";
		List<BuyerAddressModel> buyeraddresslist = BuyerAddressModel.dao.find(sql);
		if(log.isInfoEnabled()){log.info("buyeraddresslist="+buyeraddresslist);}
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("state", "fal");
		if(buyeraddresslist.size()!=0){
			System.out.println(1);
			if(state==0){
				for(BuyerAddressModel ad : buyeraddresslist){
					ad.set("state", 1).update();
				}
			}
		}else{
			System.out.println(2);
			state = 0;
		}
		System.out.println(state);
		BuyerAddressModel buyeraddress = new BuyerAddressModel();
		boolean issave = buyeraddress.set("user_phone", userphone).set("consignee_phone", phone).set("country", country).set("province", province)
									 .set("city", city).set("district", district).set("address", address).set("consignee", consignee)
									 .set("zipcode", zipcode).set("state", state).save();
		if(issave){
			rs.put("state", "suc");
		}
		this.renderJson(rs);
	}
	
	/**
	 * 修改收货地址
	 * @author lifuqiang
	 * 2016-10-10
	 */
	@Clear
	public void editAddress(){
		String addressid = this.getPa("addressid");
		String phone = this.getPa("phone");
		String consignee = this.getPa("consignee");
		String country = this.getPa("country");
		String province = this.getPa("province");
		String city = this.getPa("city");
		String district = this.getPa("district");
		String address = this.getPa("address");
		String zipcode = this.getPa("zipcode");
		String sql = "select * from buyer_address where id='"+addressid+"' ";
		BuyerAddressModel buyeraddress = BuyerAddressModel.dao.findFirst(sql);
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("state", "fal");
		if(buyeraddress!=null){
			boolean issave = buyeraddress.set("consignee_phone", phone).set("country", country).set("province", province)
			 .set("city", city).set("district", district).set("address", address).set("consignee", consignee)
			 .set("zipcode", zipcode).set("state", 1).update();
			if(issave){
				rs.put("state", "suc");
			}
		}
		this.renderJson(rs);
	}
	
	/**
	 * 加为关注/取消关注
	 * @author lifuqiang
	 * 2016-10-8
	 */
	@Clear
	public void changeFavorite(){
		String phone = this.getPa("phone");
		String tophone = this.getPa("tophone");
		String exists = this.getPa("exists");//true加为关注，false为取消关注
		String sql = "select * from favorite where from_phone='"+phone+"' and to_phone='"+tophone+"'";
		FavoriteModel favorite = FavoriteModel.dao.findFirst(sql);
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("state", "fal");
		if("true".equals(exists)){//添加关注
			if(favorite ==null){
				if(new FavoriteModel().set("from_phone", phone).set("to_phone", tophone).save()){
					rs.put("state", "suc");
				}
			}
		}else if("false".equals(exists)){//取消关注
			if(new FavoriteModel().deleteById( favorite.get("id"))){
				rs.put("state", "suc");
			}
		}
		this.renderJson(rs);
	}
	
	/**
	 * 卖家退货处理h5页面
	 * @author liushaomin
	 * 2016年11月21日
	 */
	@Clear
	public void sellerReturnDetail() {
		String returngoodsid = getPa("returngoodsid");
		ReturnGoodsModel returngoods = ReturnGoodsModel.dao.findById(returngoodsid);
		Map<String, Object> map = JsonUtils.deserialize(returngoods.get("data").toString());
		this.setAttr("traces", map.get("Traces"));
		this.setAttr("returngoods", returngoods);
		this.renderJsp("./sellerReturn.jsp");
	}
	
	/**
	 * 买家退货处理h5页面
	 * @author liushaomin
	 * 2016年11月21日
	 */
	@Clear
	public void buyersReturnDetail() {
		String returngoodsid = getPa("returngoodsid");
		ReturnGoodsModel returngoods = ReturnGoodsModel.dao.findById(returngoodsid);
		Map<String, Object> map = JsonUtils.deserialize(returngoods.get("data").toString());
		this.setAttr("traces", map.get("Traces"));
		this.setAttr("returngoods", returngoods);
		this.renderJsp("./buyersReturn.jsp");
	}
	
	/**
	 * 获取用户兴趣的类别（滚动展示的类别）
	 * @author lifuqiang
	 * 2016-12-12
	 */
	@Clear
	public void getUserHobbyCategroy(){
		String phone = this.getPa("phone");
		List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
		Map<String, Object> rs = new HashMap<String, Object>();
		String catestr;
		if(phone.equals("") || phone.equals(null)){
			catestr = CATEGROY_ID;
		}else{
			BuyerStatisticsModel bs = BuyerStatisticsModel.getStatistics(phone);
			catestr = bs.get("categroy_id").toString();
		}
		String[] catebytes = catestr.split(",");
		for (int i = 0; i < catebytes.length; i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			GoodsCategroyModel gcm = GoodsCategroyModel.dao.findById(catebytes[i]);
			map.put("id",catebytes[i]);
			map.put("c_name", gcm.get("c_name"));
			list.add(map);
		}
		rs.put("goodscategroy", list);
		this.renderJson(rs);
	}
	
	/**
	 * 获取用户编辑时的兴趣类别（未被选择的类别）
	 * @author lifuqiang
	 * 2016-12-12
	 */
	@Clear
	public void getEditHobbyCategroy(){
		String phone = this.getPa("phone");
		BuyerStatisticsModel bs = BuyerStatisticsModel.getStatistics(phone);
		List<Map<String, Object>> list_NoChoice = new ArrayList<Map<String,Object>>();
		List<GoodsCategroyModel> gcm_list = GoodsCategroyModel.dao.getCategroyByCategroyid(bs.getStr("categroy_id"));
		for (GoodsCategroyModel gcm : gcm_list) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("id", gcm.get("id").toString());
			map.put("c_name", gcm.get("c_name"));
			list_NoChoice.add(map);
		}
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("goodscategroy", list_NoChoice);
		this.renderJson(rs);
	}
	
	/**
	 * 用户编辑兴趣的类别（更新操作）
	 * @author lifuqiang
	 * 2016-12-12
	 */
	@Clear
	public void editHobbyCategroy(){
		String sql = "select * from buyer_statistics where buyer_phone = '"+getPa("phone")+"'";
		BuyerStatisticsModel bs = BuyerStatisticsModel.dao.findFirst(sql);
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("state", "fal");
		boolean boo = bs.set("categroy_id", getPa("categroyids")).update();
		if(boo){
			rs.put("state", "suc");
		}
		this.renderJson(rs);
	}
	
	/**
	 * 首页-用户感兴趣的商品（6个）
	 * 首页-热门的商品（销量最高的）（6个）
	 * @author lifuqiang
	 * ios再用
	 * 2016-12-12
	 */
	@Clear
	public void getUserHobbyGoods(){
		Map<String, Object> rs = new HashMap<String, Object>();
		String phone = this.getPa("phone");
		//用户感兴趣的商品（6个）--目前为最新六个商品
		String categroy_id ;
		if( !phone.equals("")){
			categroy_id = BuyerStatisticsModel.getStatistics(phone).getStr("categroy_id");
		}else{
			categroy_id = CATEGROY_ID;
		}
		List<GoodsModel> goods_list_hobby = GoodsModel.dao.getGoodsByCategroyid(categroy_id);
		List<Map<String, Object>> list_Home = new ArrayList<Map<String,Object>>();
		Map<String, Object> map_HobbyGoods = new HashMap<String, Object>();
		for (GoodsModel item : goods_list_hobby) {
			item.set("thumb", ImgPath + item.get("thumb"));
			item.put("shop_name", BuyerStatisticsModel.getShop_name(item.getStr("seller_id")));
			item.put("shop_address", BuyerStatisticsModel.getAddress(item.getStr("seller_id")));
		}
		map_HobbyGoods.put("Homename", "猜你喜欢");
		map_HobbyGoods.put("Homelist", goods_list_hobby);
		list_Home.add(map_HobbyGoods);//用户感兴趣的商品（6个）
		//热门的商品（销量最高的）（6个）
		List<GoodsModel> goods_list_Hot = GoodsModel.dao.getHotGoods();
		for (GoodsModel item : goods_list_Hot) {
			item.set("thumb", ImgPath + item.get("thumb"));
			item.put("shop_name", BuyerStatisticsModel.getShop_name(item.getStr("seller_id")));
			item.put("shop_address", BuyerStatisticsModel.getAddress(item.getStr("seller_id")));
		}
		Map<String, Object> map_HotGoods = new HashMap<String, Object>();
		map_HotGoods.put("Homename", "热门商品");
		map_HotGoods.put("Homelist", goods_list_Hot);
		list_Home.add(map_HotGoods);//热门的商品（销量最高的）（6个）
		rs.put("Home", list_Home);
		this.renderJson(rs);
	}
	
	/**
	 * android 专用
	 * 首页-用户感兴趣的商品（6个）  
	 * 首页-热门的商品（销量最高的）（6个）
	 * @author liushaomin
	 * 2017年6月20日
	 */
	@Clear
	public void getUserHobbyGoods_android(){
		Map<String, Object> rs = new HashMap<String, Object>();
		String phone = this.getPa("phone");
		//用户感兴趣的商品（6个）--目前为最新六个商品
		String categroy_id ;
		if( !phone.equals("")){
			categroy_id = BuyerStatisticsModel.getStatistics(phone).getStr("categroy_id");
		}else{
			categroy_id = CATEGROY_ID;
		}
		List<GoodsModel> goods_list_hobby = GoodsModel.dao.getGoodsByCategroyid(categroy_id);
		for (GoodsModel item : goods_list_hobby) {
			item.set("thumb", ImgPath + item.get("thumb"));
			item.put("shop_name", BuyerStatisticsModel.getShop_name(item.getStr("seller_id")));
			item.put("shop_address", BuyerStatisticsModel.getAddress(item.getStr("seller_id")));
			item.put("Homename", "猜你喜欢");
			item.put("type", "1");
		}
		List<GoodsModel> goods_list_Hot = GoodsModel.dao.getHotGoods();
		for (GoodsModel item : goods_list_Hot) {
			item.set("thumb", ImgPath + item.get("thumb"));
			item.put("shop_name", BuyerStatisticsModel.getShop_name(item.getStr("seller_id")));
			item.put("shop_address", BuyerStatisticsModel.getAddress(item.getStr("seller_id")));
			item.put("Homename", "热门商品");
			item.put("type", "2");
			goods_list_hobby.add(item);
		}
		rs.put("Home", goods_list_hobby);
		this.renderJson(rs);
	}
	
	/**
	 * 搜索商品-获取推荐类别
	 * @author lifuqiang
	 * 2016-12-14
	 */
	@Clear
	public void getHotSearch(){
		//热门的商品类别（8个）
		List<GoodsCategroyModel> goodscate_list_HotSearch = GoodsCategroyModel.dao.getHotGoodsCateBySearch(CATEGROY_IDS);
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("HotSearch", goodscate_list_HotSearch);
		this.renderJson(rs);
	}
	
	/**
	 * 添加意见和建议
	 * @author liushaomin
	 * 2017年3月10日
	 */
	@Clear
	public void addFeedBack(){
		String phone = getPa("phone");
		String content = getPa("content");
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("state", "fal");
		if(FeedBackModel.add(phone, content)){
			rs.put("state", "suc");
		}
		this.renderJson(rs);
	}
	
	/**
	 * 上传员工邀请码
	 * @author liushaomin
	 * 2017年3月20日
	 */
	@Clear
	public void employee_invite_code(){
		String phone = this.getPara("phone");
		String employee_invite_code = this.getPara("employee_invite_code");
		Map<String, Object> rs = new HashMap<String, Object>();
		rs.put("state", "fal");
		EmployeeManageModel Employee =  EmployeeManageModel.getByEmployee_invite_code(employee_invite_code);
		if(Employee != null){
			BuyerStatisticsModel buyersta = BuyerStatisticsModel.getStatistics(phone);
			if(StringUtils.isEmpty(buyersta.getStr("employee_invite_code"))){
				if(buyersta.set("employee_invite_code", employee_invite_code).update()){
					rs.put("state", "suc");
				}
			}else{
				rs.put("state", "isfinish");
			}
		}else{
			rs.put("state", "noexist");
		}
		this.renderJson(rs);
	}
	
	/**
	 * 获取最新版本号 android专用
	 * @author liushaomin
	 * 2017年3月24日
	 */
	@Clear
	public void app_version(){
		String version_number = this.getPara("version_number").toString().trim();
		String type = this.getPara("type");
		Map<String, Object> rs = new HashMap<String, Object>();
		AppVersionModel appversion = AppVersionModel.getVersion(type);
		if(appversion.getStr("version_number").toString().trim().equals(version_number)){
			rs.put("state", "newest");
		}else{
			rs.put("state", "update");
			rs.put("content", appversion.getStr("content"));
			rs.put("version_number", appversion.getStr("version_number"));
			rs.put("link", "http://www.rebogou.com/download/android/" + appversion.getStr("version_number").trim()+ ".apk");
		}
		this.renderJson(rs);
	}
	
	
	
	@Clear
	public void app_version2(){
		this.renderJson(HuanXinUtils.getSingleUser(this.getPara("phone").toString()));
	}
	
	@Clear
	public void app_version3(){
		HuanXinUtils.addUsers(getPa("phone"), getPa("passwd"), getPa("phone"));//注册环信 密码未加密
		this.renderJson(HuanXinUtils.getSingleUser(this.getPara("phone").toString()));
	}
	
	
	
}
